import { http } from './http'
import { PageQueryParams, PageResponse } from '@/config/page'

export interface TaskAuditParams {
  variables?: Record<string, any>;
  action: 'pass' | 'reject' | 'termination';
  comment: string;
  processInstanceId: string;
}
export interface FlowStartParams {
  applyDoc: string;

  remark: string;

  variables: Record<string, any>;

  action: string;
}

/**
 * 发起流程。
 */
export function startProcess (processDefKey: string, params: FlowStartParams) {
  return http().post<PageResponse<any>>(`api/document/flow/process/${processDefKey}/start`, params)
}

/**
 * 查询待办列表。
 */
export function queryTodoTasks (params: PageQueryParams) {
  return http().get<PageResponse<any>>('/api/document/flow/todo/tasks', { params })
}

/**
 * 查询已办列表。
 */
export function queryDoneTasks (params: PageQueryParams) {
  return http().get<PageResponse<any>>('/api/document/flow/done/tasks', { params })
}

/**
 * 查询请求列表。
 */
export function queryRequestTasks (params: PageQueryParams) {
  return http().get<PageResponse<any>>('/api/document/flow/request/tasks', { params })
}

/**
 * 审批。
 */
export function auditTask (taskId: string, params: TaskAuditParams) {
  return http().post<any>(`/api/document/flow/audit/${taskId}`, params)
}

/**
 * 获取流程实例信息.
 */
export function getProcess (processInstanceId: string) {
  return http().get<any>(`/api/document/flow/inst/${processInstanceId}`)
}

/**
 * 查询待办数量。
 */
export function queryTodoTaskCount () {
  return http().get<number>('/api/document/flow/todo/tasks/count')
}
